const TOKEN_KEY = "Asiainfo-Token";
const TENANT_ID = "tenantId";
const REFRESH_TOKEN_KEY = "Asiainfo-Refresh-Token";

const tokenStorage = useStorage<null | string>(TOKEN_KEY, null);
const tenantIdStorage = useStorage<null | string | number>(TENANT_ID, null);
const refreshTokenStorage = useStorage<null | string>(REFRESH_TOKEN_KEY, null);

const isLogin = () => {
  return !!tokenStorage.value;
};

const getToken = () => tokenStorage.value;

const setToken = (token: string) => (tokenStorage.value = token);

const clearToken = () => (tokenStorage.value = null);

const getTenantId = () => tenantIdStorage.value;

const setTenantId = (tenantId: string | number) => (tenantIdStorage.value = tenantId);

const clearTenantId = () => (tenantIdStorage.value = null);

const getRefreshToken = () => refreshTokenStorage.value || "";

const setRefreshToken = (refreshToken: string) => (refreshTokenStorage.value = refreshToken);

const clearRefreshToken = () => (refreshTokenStorage.value = null);

export {
  isLogin,
  getTenantId,
  setTenantId,
  clearTenantId,
  getToken,
  setToken,
  clearToken,
  getRefreshToken,
  setRefreshToken,
  clearRefreshToken
};
